The following example creates a registry key and two subkeys. It retrieves the first key's value and then retrieves the values of the first key as well as its subkeys. It then deletes the second subkey and prints the values of the first key and its subkeys to confirm the deletion of the second subkey.
Private Sub CreateAndDeleteKey
SaveSetting("TestApp","FirstKey","FirstSubKey","FirstSub")
SaveSetting("TestApp","FirstKey","SecondSubKey","SecondSub")
Dim firstKey As String = GetSetting("TestApp", "FirstKey", _
"FirstSubKey")
Dim allSettings(,) As String = GetAllSettings("TestApp", "FirstKey")
DeleteSetting("TestApp", "FirstKey", "SecondSubKey")
firstKey = GetSetting("TestApp", "FirstKey", "SecondSubKey")
allSettings = GetAllSettings("TestApp", "Startup")
End Sub
Note The second call to GetSetting returns an empty string, because the subkey has been deleted. The first call to GetAllSettings returns two key/value pairs, the second call returns only one key/value pair.
The GetSetting method returns an empty string if the key/value pair does not exist.
Registry calls fail if either sufficient runtime permissions are not granted
(
Code:
Adding Data to the Registry |